import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [{
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: {
        title: '首页',
        icon: 'dashboard'
      }
    }]
  },

  {
    path:'/member',
    component:Layout,
    redirect: '/member/index',
    meta:{
      title: '用户管理',
      icon: 'user'
    },
    children:[{
      path: 'index',
      name: 'member_index',
      component: () => import('@/views/member/index'),
      meta: {
        title: '用户列表'
      }
    }]
  },

  {
    path:'/category',
    component:Layout,
    redirect: '/category/index',
    meta:{
      title: '分类管理',
      icon: 'example'
    },
    children:[{
      path: 'index',
      name: 'category_index',
      component: () => import('@/views/category/index'),
      meta: {
        title: '分类列表'
      }
    },{
      path: 'add',
      name: 'category_add',
      component: () => import('@/views/category/add'),
      meta: {
        title: '添加分类'
      }
    },{
      path: 'edit',
      name: 'category_edit',
      component: () => import('@/views/category/edit'),
      meta: {
        title: '编辑分类'
      }
    }]
  },

  {
    path:'/goods',
    component:Layout,
    redirect: '/goods/index',
    meta:{
      title: '商品管理',
      icon: 'goods'
    },
    children:[{
      path: 'index',
      name: 'goods_index',
      component: () => import('@/views/goods/index'),
      meta: {
        title: '商品列表'
      }
    },{
      path: 'add',
      name: 'goods_add',
      component: () => import('@/views/goods/add'),
      meta: {
        title: '添加商品'
      }
    },{
      path: 'edit',
      name: 'goods_edit',
      component: () => import('@/views/goods/edit'),
      meta: {
        title: '编辑商品'
      }
    }]
  },

  {
    path:'/order',
    component:Layout,
    redirect: '/order/index',
    meta:{
      title: '订单管理',
      icon: 'order'
    },
    children:[{
      path: 'index',
      name: 'order_index',
      component: () => import('@/views/order/index'),
      meta: {
        title: '订单列表'
      }
    }]
  },

  {
    path:'/swiper',
    component:Layout,
    redirect: '/swiper/index',
    meta:{
      title: '轮播图管理',
      icon: 'swiper'
    },
    children:[{
      path: 'index',
      name: 'swiper_index',
      component: () => import('@/views/swiper/index'),
      meta: {
        title: '轮播图列表'
      }
    },{
      path: 'add',
      name: 'swiper_add',
      component: () => import('@/views/swiper/add'),
      meta: {
        title: '添加轮播图'
      }
    },{
      path: 'edit',
      name: 'swiper_edit',
      component: () => import('@/views/swiper/edit'),
      meta: {
        title: '编辑轮播图'
      }
    }]
  },

  {
    path:'/finance',
    component:Layout,
    redirect: '/finance/index',
    meta:{
      title: '财务管理',
      icon: 'finance'
    },
    children:[{
      path: 'setting',
      name: 'finance_setting',
      component: () => import('@/views/finance/setting'),
      meta: {
        title: '财务设置'
      }
    },{
      path: 'check',
      name: 'finance_check',
      component: () => import('@/views/finance/check'),
      meta: {
        title: '提现审核'
      }
    }]
  },

  {
    path:'/system',
    component:Layout,
    redirect: '/system/wechat',
    meta:{
      title: '系统设置',
      icon: 'setting'
    },
    children:[{
      path: 'wechat',
      name: 'system_wechat',
      component: () => import('@/views/system/wechat'),
      meta: {
        title: '微信小程序设置'
      }
    },{
      path: 'alipay',
      name: 'system_alipay',
      component: () => import('@/views/system/alipay'),
      meta: {
        title: '支付宝小程序设置'
      }
    }]
  },


  // 404 page must be placed at the end !!!
  {
    path: '*',
    redirect: '/404',
    hidden: true
  }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
